package com.usermanage.controller;

import com.ordercore.Util.ResponseData.ResponseData;
import com.pinza.Bean.SkuDataGrid;
import com.pinza.Common.SkuDataGridIOC;
import com.usermanage.SecurityConfig.SpringSecurityUtils;
import com.usermanage.Service.ContractRealTimePriceService;
import com.usermanage.Service.UserService;
import com.usermanage.beanParam.ContractRealTimePriceBean;
import com.usermanage.beanParam.UserBean;
import com.usermanage.util.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Array;
import java.text.SimpleDateFormat;
import java.util.*;

@Slf4j
@RestController
@RequestMapping("/reports")
public class EOSReports {

    @Resource
    private UserService userService;
    @Resource
    private ContractRealTimePriceService contractRealTimePriceService;

    @RequestMapping("/order.page")
    public ModelAndView orderPage() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/reports/order");
        return mv;
    }

    @RequestMapping("/order.json")
    public JsonData orderJson(String key, int page, int size) throws Exception {
        Map map = new HashMap();
        map.put("formId", "ORDER_DETAIL_LIST_INFO");
        map.put("key", key);
        map.put("fields", new String[0]);
        map.put("page", page);
        map.put("size", size);
        map.put("searchSet", StaticUtil.ORDERFIELDS);
        String param = StringUtil.ObjectToJson(map);
        String result = HttpUtil.sendPost(StaticUtil.LUCENE + "/query", param);
        Map resultMap = StringUtil.JsonToMap(result);
        if (Boolean.valueOf(String.valueOf(resultMap.get("result")))) {
            List<Map> list = StringUtil.JsonToList(StringUtil.ObjectToJson(resultMap.get("data")));
            for (int i = 0; i < list.size(); i++) {
                UserBean userBean = userService.findUserDetail((String) list.get(i).get("user_id"));
                list.get(i).put("user_name", userBean.getUser_name());
            }
            return JsonData.successlayertable(list, 0, Integer.valueOf(String.valueOf(resultMap.get("count"))));
        } else {
            return JsonData.fail();
        }
    }

    @RequestMapping(value = "/order/export.json")
    public void orderExportExcel(HttpServletResponse response, String key) throws IOException, Exception {
        // 第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("订单报表");
        //列宽
        sheet.setColumnWidth(0, 30 * 100);
        sheet.setColumnWidth(1, 80 * 100);
        sheet.setColumnWidth(2, 80 * 100);
        sheet.setColumnWidth(3, 80 * 100);
        sheet.setColumnWidth(4, 80 * 100);
        sheet.setColumnWidth(5, 80 * 100);
        sheet.setColumnWidth(6, 80 * 100);
        sheet.setColumnWidth(7, 80 * 100);
        sheet.setColumnWidth(8, 80 * 100);
        sheet.setColumnWidth(9, 80 * 100);
        sheet.setColumnWidth(10, 80 * 100);
        sheet.setColumnWidth(11, 80 * 100);
        sheet.setColumnWidth(12, 80 * 100);
        sheet.setColumnWidth(13, 80 * 100);
        sheet.setColumnWidth(14, 80 * 100);
        sheet.setColumnWidth(15, 80 * 100);
        sheet.setColumnWidth(16, 80 * 100);
        sheet.setColumnWidth(17, 80 * 100);
        sheet.setColumnWidth(18, 80 * 100);
        sheet.setColumnWidth(19, 80 * 100);
        sheet.setColumnWidth(20, 80 * 100);
        sheet.setColumnWidth(21, 80 * 100);
        sheet.setColumnWidth(22, 80 * 100);
        sheet.setColumnWidth(23, 80 * 100);
        sheet.setColumnWidth(24, 80 * 100);
        sheet.setColumnWidth(25, 80 * 100);
        sheet.setColumnWidth(26, 80 * 100);
        sheet.setColumnWidth(27, 80 * 100);
        sheet.setColumnWidth(28, 80 * 100);

        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow row = sheet.createRow((int) 0);
        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
        HSSFCell cell = row.createCell(0);
        cell.setCellValue("序号");
        cell.setCellStyle(style);
        cell = row.createCell(1);
        cell.setCellValue("订单编号");
        cell.setCellStyle(style);
        cell = row.createCell(2);
        cell.setCellValue("项目名称");
        cell.setCellStyle(style);
        cell = row.createCell(3);
        cell.setCellValue("客户名称");
        cell.setCellStyle(style);
        cell = row.createCell(4);
        cell.setCellValue("客户联系人");
        cell.setCellStyle(style);
        cell = row.createCell(5);
        cell.setCellValue("收货人联系方式");
        cell.setCellStyle(style);
        cell = row.createCell(6);
        cell.setCellValue("订单状态");
        cell.setCellStyle(style);
        cell = row.createCell(7);
        cell.setCellValue("材料编码");
        cell.setCellStyle(style);
        cell = row.createCell(8);
        cell.setCellValue("材料名称");
        cell.setCellStyle(style);
        cell = row.createCell(9);
        cell.setCellValue("规格参数");
        cell.setCellStyle(style);
        cell = row.createCell(10);
        cell.setCellValue("品牌");
        cell.setCellStyle(style);
        cell = row.createCell(11);
        cell.setCellValue("型号");
        cell.setCellStyle(style);
        cell = row.createCell(12);
        cell.setCellValue("单位");
        cell.setCellStyle(style);
        cell = row.createCell(13);
        cell.setCellValue("单价");
        cell.setCellStyle(style);
        cell = row.createCell(14);
        cell.setCellValue("下单员");
        cell.setCellStyle(style);
        cell = row.createCell(15);
        cell.setCellValue("发货人");
        cell.setCellStyle(style);
        cell = row.createCell(16);
        cell.setCellValue("收货人");
        cell.setCellStyle(style);
        cell = row.createCell(17);
        cell.setCellValue("订货数量");
        cell.setCellStyle(style);
        cell = row.createCell(18);
        cell.setCellValue("已发货数量");
        cell.setCellStyle(style);
        cell = row.createCell(19);
        cell.setCellValue("已收货数量");
        cell.setCellStyle(style);
        cell = row.createCell(20);
        cell.setCellValue("订单总金额");
        cell.setCellStyle(style);
        cell = row.createCell(21);
        cell.setCellValue("发货金额");
        cell.setCellStyle(style);
        cell = row.createCell(22);
        cell.setCellValue("已收货金额");
        cell.setCellStyle(style);
        cell = row.createCell(23);
        cell.setCellValue("订货备注");
//        cell.setCellStyle(style);
//        cell = row.createCell(24);
//        cell.setCellValue("发货备注");
//        cell.setCellStyle(style);
        cell = row.createCell(24);
        cell.setCellValue("收货备注");
        cell.setCellStyle(style);
        cell = row.createCell(25);
        cell.setCellValue("产品说明");
        cell.setCellStyle(style);
        cell = row.createCell(26);
        cell.setCellValue("要求到货时间");
        cell.setCellStyle(style);
        cell = row.createCell(27);
        cell.setCellValue("收货时间");
        cell.setCellStyle(style);
        cell = row.createCell(28);
        cell.setCellValue("标准供货周期");
        cell.setCellStyle(style);

        // 第五步，写入实体数据 实际应用中这些数据从数据库得到，

        Map map = new HashMap();
        map.put("formId", "ORDER_DETAIL_LIST_INFO");
        map.put("key", key);
        map.put("fields", new String[0]);
        map.put("page", 0);
        map.put("size", 0);
        map.put("searchSet", StaticUtil.ORDERFIELDS);
        String param = StringUtil.ObjectToJson(map);
        String result = HttpUtil.sendPost(StaticUtil.LUCENE + "/query", param);
//       if(StringUtils.isBlank(result)){
//            return JsonData.fail("网络异常，请稍后重试");
//       }
        Map resultMap = StringUtil.JsonToMap(result);
        if (Boolean.valueOf(resultMap.get("result").toString())) {
            try {
                List<Map> list = (List<Map>) resultMap.get("data");
                for (int i = 0; i < list.size(); i++) {
                    UserBean userBean = userService.findUserDetail((String) list.get(i).get("user_id"));
                    row = sheet.createRow((int) i + 1);
                    // 第四步，创建单元格，并设置值
                    row.createCell(0).setCellValue((i + 1));
                    row.createCell(1).setCellValue(list.get(i).get("orderBill_id") == null ? "" : list.get(i).get("orderBill_id").toString());
                    row.createCell(2).setCellValue(list.get(i).get("project_name") == null ? "" : list.get(i).get("project_name").toString());
                    row.createCell(3).setCellValue(list.get(i).get("userGroup_name") == null ? "" : list.get(i).get("userGroup_name").toString());
                    row.createCell(4).setCellValue(list.get(i).get("consignee_information") == null ? "" : list.get(i).get("consignee_information").toString());
                    row.createCell(5).setCellValue(list.get(i).get("consignee_address") == null ? "" : list.get(i).get("consignee_address").toString());
                    switch (String.valueOf(list.get(i).get("orderBill_customStat"))) {
                        case "1000":
                            row.createCell(6).setCellValue("已保存（待供方确认）");
                            break;
                        case "1001":
                            row.createCell(6).setCellValue("下单中（待需方确认）");
                            break;
                        case "1002":
                            row.createCell(6).setCellValue("付款中(已付款" + String.valueOf(list.get(i).get("payment")) + ")");
                            break;
                        case "1003":
                            row.createCell(6).setCellValue("已删除");
                            break;
                        case "1004":
                            row.createCell(6).setCellValue("已完成(已付款" + String.valueOf(list.get(i).get("payment")) + ")");
                            break;
                        default:
                            row.createCell(6).setCellValue("未知");
                            break;
                    }
                    row.createCell(7).setCellValue(list.get(i).get("sku_code") == null ? "" : list.get(i).get("sku_code").toString());
                    row.createCell(8).setCellValue(list.get(i).get("sku_name") == null ? "" : list.get(i).get("sku_name").toString());
                    row.createCell(9).setCellValue(list.get(i).get("sku_slug_set") == null ? "" : list.get(i).get("sku_slug_set").toString());
                    row.createCell(10).setCellValue(list.get(i).get("sku_brand") == null ? "" : list.get(i).get("sku_brand").toString());
                    row.createCell(11).setCellValue(list.get(i).get("sku_model") == null ? "" : list.get(i).get("sku_model").toString());
                    row.createCell(12).setCellValue(list.get(i).get("sku_unit") == null ? "" : list.get(i).get("sku_unit").toString());
                    row.createCell(13).setCellValue(list.get(i).get("sku_contract_price") == null ? "" : list.get(i).get("sku_contract_price").toString());
                    row.createCell(14).setCellValue(userBean.getUser_name() == null ? "" : userBean.getUser_name());
                    row.createCell(15).setCellValue("");
                    row.createCell(16).setCellValue("");
                    row.createCell(17).setCellValue(list.get(i).get("purNum") == null ? "" : list.get(i).get("purNum").toString());
                    row.createCell(18).setCellValue(list.get(i).get("sendNum") == null ? "" : list.get(i).get("sendNum").toString());
                    row.createCell(19).setCellValue(list.get(i).get("acceptNum") == null ? "" : list.get(i).get("acceptNum").toString());
                    row.createCell(20).setCellValue(list.get(i).get("price") == null ? "" : list.get(i).get("price").toString());
                    row.createCell(21).setCellValue("");
                    row.createCell(22).setCellValue("");
                    row.createCell(23).setCellValue("");
//                    row.createCell(24).setCellValue("");
                    row.createCell(24).setCellValue("");
                    row.createCell(25).setCellValue(list.get(i).get("sku_remark") == null ? "" : list.get(i).get("sku_remark").toString());
                    row.createCell(26).setCellValue(list.get(i).get("arriveTime") == null ? "" : list.get(i).get("arriveTime").toString());
                    row.createCell(27).setCellValue("");
                    row.createCell(28).setCellValue(list.get(i).get("sku_lead_time") == null ? "" : list.get(i).get("sku_lead_time").toString());



                }
                // 第六步，将文件存到指定位置
                try {
                    String filename = "订单报表";
                    String fileName = new String(filename.getBytes(), "iso8859-1") + ".xls";
                    response.setContentType("application/octet-stream");
                    response.setHeader("Content-disposition", "attachment;filename="+ fileName);//默认Excel名称
                    response.flushBuffer();
                    response.setCharacterEncoding("UTF-8");
                    wb.write(response.getOutputStream());
                } catch (Exception e) {
                    e.printStackTrace();
//                  return JsonData.fail("导出失败，请稍后重试");
                } finally {
                    wb.close();
                }
//              return JsonData.success();
            } catch (Exception e) {
//              return JsonData.fail("导出失败，请稍后重试");
            }
        } else {
//          return JsonData.fail("导出失败，请稍后重试");
        }
    }

    @RequestMapping("/nsl.page")
    public ModelAndView nslPage() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/reports/nsl");
        return mv;
    }

    @RequestMapping("/sku.page")
    public ModelAndView skuPage() {
        ModelAndView mv = new ModelAndView();
        mv.addObject("url", StaticUtil.LUCENE);
        mv.setViewName("/reports/sku");
        return mv;
    }

    @RequestMapping("/spu.page")
    public ModelAndView spuPage() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/reports/spu");
        return mv;
    }

    @RequestMapping("/spu.json")
    public ResponseData spuJson(String key, int page, int size) {
        SkuDataGrid skuDataGrid = new SkuDataGrid();
        skuDataGrid.setPage(page);
        skuDataGrid.setLimit(size);
        skuDataGrid.setSku_status("00");
        skuDataGrid.setKey(key);
        ResponseData responseData = SkuDataGridIOC.getSkuDataGrid(skuDataGrid);
        return responseData;
    }

    @RequestMapping(value = "/spu/export.json")
    public void spuExportExcel(HttpServletResponse response, String key) throws IOException, Exception {
        // 第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("已上架产品报表");
        //列宽
        sheet.setColumnWidth(0, 30 * 100);
        sheet.setColumnWidth(1, 80 * 100);
        sheet.setColumnWidth(2, 80 * 100);
        sheet.setColumnWidth(3, 80 * 100);
        sheet.setColumnWidth(4, 80 * 100);
        sheet.setColumnWidth(5, 80 * 100);
        sheet.setColumnWidth(6, 80 * 100);
        sheet.setColumnWidth(7, 80 * 100);
        sheet.setColumnWidth(8, 80 * 100);
        sheet.setColumnWidth(9, 80 * 100);
        sheet.setColumnWidth(10, 80 * 100);
        sheet.setColumnWidth(11, 80 * 100);
        sheet.setColumnWidth(12, 80 * 100);
        sheet.setColumnWidth(13, 80 * 100);

        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow row = sheet.createRow((int) 0);
        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
        HSSFCell cell = row.createCell(0);
        cell.setCellValue("序号");
        cell.setCellStyle(style);
        cell = row.createCell(1);
        cell.setCellValue("一级分类");
        cell.setCellStyle(style);
        cell = row.createCell(2);
        cell.setCellValue("二级分类");
        cell.setCellStyle(style);
        cell = row.createCell(3);
        cell.setCellValue("三级分类");
        cell.setCellStyle(style);
        cell = row.createCell(4);
        cell.setCellValue("SPU编号");
        cell.setCellStyle(style);
        cell = row.createCell(5);
        cell.setCellValue("SPU名称");
        cell.setCellStyle(style);
        cell = row.createCell(6);
        cell.setCellValue("SKU编号");
        cell.setCellStyle(style);
        cell = row.createCell(7);
        cell.setCellValue("SKU名称");
        cell.setCellStyle(style);
        cell = row.createCell(8);
        cell.setCellValue("品牌");
        cell.setCellStyle(style);
        cell = row.createCell(9);
        cell.setCellValue("单位");
        cell.setCellStyle(style);
        cell = row.createCell(10);
        cell.setCellValue("型号");
        cell.setCellStyle(style);
        cell = row.createCell(11);
        cell.setCellValue("规格参数");
        cell.setCellStyle(style);
        cell = row.createCell(12);
        cell.setCellValue("成本价格");
        cell.setCellStyle(style);
        cell = row.createCell(13);
        cell.setCellValue("官方价格");
        cell.setCellStyle(style);

        // 第五步，写入实体数据 实际应用中这些数据从数据库得到，

        SkuDataGrid skuDataGrid = new SkuDataGrid();
        skuDataGrid.setPage(0);
        skuDataGrid.setLimit(0);
        skuDataGrid.setSku_status("00");
        skuDataGrid.setSpu_status("00");
        skuDataGrid.setKey(key);
        ResponseData responseData = SkuDataGridIOC.getSkuDataGrid(skuDataGrid);
//       if(StringUtils.isBlank(result)){
//            return JsonData.fail("网络异常，请稍后重试");
//       }
        if (responseData.isRet()) {
            try {
                List<Map> list = (List<Map>) responseData.getData();
                for (int i = 0; i < list.size(); i++) {
                    row = sheet.createRow((int) i + 1);
                    // 第四步，创建单元格，并设置值
                    row.createCell(0).setCellValue((i + 1));
                    row.createCell(1).setCellValue(list.get(i).get("clsOne") == null ? "" : list.get(i).get("clsOne").toString());
                    row.createCell(2).setCellValue(list.get(i).get("clsTwo") == null ? "" : list.get(i).get("clsTwo").toString());
                    row.createCell(3).setCellValue(list.get(i).get("clsThree") == null ? "" : list.get(i).get("clsThree").toString());
                    row.createCell(4).setCellValue(list.get(i).get("spu_code") == null ? "" : list.get(i).get("spu_code").toString());
                    row.createCell(5).setCellValue(list.get(i).get("spu_name") == null ? "" : list.get(i).get("spu_name").toString());
                    row.createCell(6).setCellValue(list.get(i).get("sku_code") == null ? "" : list.get(i).get("sku_code").toString());
                    row.createCell(7).setCellValue(list.get(i).get("sku_name") == null ? "" : list.get(i).get("sku_name").toString());
                    row.createCell(8).setCellValue(list.get(i).get("sku_brand") == null ? "" : list.get(i).get("sku_brand").toString());
                    row.createCell(9).setCellValue(list.get(i).get("sku_unit") == null ? "" : list.get(i).get("sku_unit").toString());
                    row.createCell(10).setCellValue(list.get(i).get("sku_model") == null ? "" : list.get(i).get("sku_model").toString());
                    row.createCell(11).setCellValue(list.get(i).get("sku_slugSet") == null ? "" : list.get(i).get("sku_slugSet").toString());
                    row.createCell(12).setCellValue(list.get(i).get("sku_cost_price") == null ? "" : list.get(i).get("sku_cost_price").toString());
                    row.createCell(13).setCellValue(list.get(i).get("sku_official_price") == null ? "" : list.get(i).get("sku_official_price").toString());
                }
                // 第六步，将文件存到指定位置
                try {
                    String filename = "已上架产品报表";
                    String fileName = new String(filename.getBytes(), "iso8859-1") + ".xls";
                    response.setContentType("application/octet-stream");
                    response.setHeader("Content-disposition", "attachment;filename="+ fileName);//默认Excel名称
                    response.flushBuffer();
                    response.setCharacterEncoding("UTF-8");
                    wb.write(response.getOutputStream());
                } catch (Exception e) {
                    e.printStackTrace();
//                  return JsonData.fail("导出失败，请稍后重试");
                } finally {
                    wb.close();
                }
//              return JsonData.success();
            } catch (Exception e) {
//              return JsonData.fail("导出失败，请稍后重试");
            }
        } else {
//          return JsonData.fail("导出失败，请稍后重试");
        }
    }

    @RequestMapping("/contract/sku.page")
    public ModelAndView contractSkuPage() {
        ModelAndView mv = new ModelAndView();
        if(SpringSecurityUtils.getCurrentUser().getCompany_id().equals("1")){
            mv.addObject("admin",true);
        }else{
            mv.addObject("admin",false);
        }
        mv.addObject("companyId",SpringSecurityUtils.getCurrentUser().getCompany_id());
        mv.setViewName("/reports/contractSku");
        return mv;
    }

    @RequestMapping("/contract/sku.json")
    public JsonData contractSkuJson(String key, String id, String page, String size) {
        List<ContractRealTimePriceBean> list = contractRealTimePriceService.findAllList(key, id, page, size, "00");
        int count = contractRealTimePriceService.getAllListCount(key, id, "00");
        return JsonData.successlayertable(list, 0, count);
    }

    @RequestMapping(value = "/contract/sku/export.json")
    public void skuExportExcel(HttpServletResponse response, String key,String id) throws IOException, Exception {
        // 第一步，创建一个webbook，对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
        HSSFSheet sheet = wb.createSheet("合同SKU上架报表");
        //列宽
        sheet.setColumnWidth(0, 60 * 100);
        sheet.setColumnWidth(1, 160 * 100);
        sheet.setColumnWidth(2, 30 * 100);
        sheet.setColumnWidth(3, 30 * 100);
        sheet.setColumnWidth(4, 60 * 100);
        sheet.setColumnWidth(5, 100 * 100);
        sheet.setColumnWidth(6, 40 * 100);
        sheet.setColumnWidth(7, 40 * 100);
        sheet.setColumnWidth(8, 60 * 100);

        // 第三步，在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
        HSSFRow row = sheet.createRow((int) 0);
        // 第四步，创建单元格，并设置值表头 设置表头居中
        HSSFCellStyle style = wb.createCellStyle();
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
        HSSFCell cell = row.createCell(0);
        cell.setCellValue("材料编码");
        cell.setCellStyle(style);
        cell = row.createCell(1);
        cell.setCellValue("材料名称");
        cell.setCellStyle(style);
        cell = row.createCell(2);
        cell.setCellValue("单位");
        cell.setCellStyle(style);
        cell = row.createCell(3);
        cell.setCellValue("品牌");
        cell.setCellStyle(style);
        cell = row.createCell(4);
        cell.setCellValue("型号");
        cell.setCellStyle(style);
        cell = row.createCell(5);
        cell.setCellValue("规格参数");
        cell.setCellStyle(style);
        cell = row.createCell(6);
        cell.setCellValue("备注");
        cell.setCellStyle(style);
        cell = row.createCell(7);
        cell.setCellValue("供货周期");
        cell.setCellStyle(style);
        cell = row.createCell(8);
        cell.setCellValue("上架时间");
        cell.setCellStyle(style);
        // 第五步，写入实体数据 实际应用中这些数据从数据库得到，

        List<ContractRealTimePriceBean> list = contractRealTimePriceService.findAllList(key, id, "0", "0", "00");
//       if(StringUtils.isBlank(result)){
//            return JsonData.fail("网络异常，请稍后重试");
//       }
                for (int i = 0; i < list.size(); i++) {
                    row = sheet.createRow((int) i + 1);
                    // 第四步，创建单元格，并设置值
                    row.createCell(0).setCellValue(list.get(i).getSku_code() );
                    row.createCell(1).setCellValue(list.get(i).getSku_name());
                    row.createCell(2).setCellValue(list.get(i).getSku_unit() );
                    row.createCell(3).setCellValue(list.get(i).getSku_brand() );
                    row.createCell(4).setCellValue(list.get(i).getSku_model() );
                    row.createCell(5).setCellValue(list.get(i).getSku_slug_set() );
                    row.createCell(6).setCellValue(list.get(i).getSku_content() );
                    row.createCell(7).setCellValue(list.get(i).getSku_lead_time());
                    row.createCell(8).setCellValue(list.get(i).getUpdate_time() );
                }
                // 第六步，将文件存到指定位置
                try {

                    String filename = "合同SKU上架报表";
                    String fileName = new String(filename.getBytes(), "iso8859-1") + ".xls";
                    response.setContentType("application/octet-stream");
                    response.setHeader("Content-disposition", "attachment;filename="+ fileName);//默认Excel名称
                    response.flushBuffer();
                    response.setCharacterEncoding("UTF-8");
                    wb.write(response.getOutputStream());
                } catch (Exception e) {
                    e.printStackTrace();
//                  return JsonData.fail("导出失败，请稍后重试");
                } finally {
                    wb.close();
                }
//              return JsonData.success();
    }
}
